﻿<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:controls="clr-namespace:Corina.Controls.Win;assembly=Corina.Controls.Win"
      xmlns:converters="clr-namespace:Corina.Converters.Win;assembly=Corina.Converters.Win"
      xmlns:localViewmodel="clr-namespace:Corina.Addins.Xiami"
      FontSize="14">
    <Page.DataContext>
        <localViewmodel:XiamiViewmodel />
    </Page.DataContext>
    <Page.Resources>
        <converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        <converters:BooleanToVisibilityInverseConverter x:Key="BooleanToVisibilityInverseConverter" />
    </Page.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <TextBox Text="{Binding Keywords, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

            <Button Grid.Column="1"
                    MinWidth="60"
                    Margin="12,0,0,0"
                    Command="{Binding SearchCommand}"
                    Content="搜索" />
        </Grid>

        <Grid Grid.Row="1" Margin="0,12">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="12" />
                <ColumnDefinition Width="200" />
            </Grid.ColumnDefinitions>

            <ListBox Grid.Row="1" ItemsSource="{Binding ResultCollection}">
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="ListBoxItem">
                                    <Grid Margin="6">
                                        <Grid Visibility="{Binding IsSelected, Converter={StaticResource BooleanToVisibilityInverseConverter}, RelativeSource={RelativeSource TemplatedParent}}">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition />
                                                <ColumnDefinition />
                                                <ColumnDefinition />
                                            </Grid.ColumnDefinitions>
                                            <TextBlock Text="{Binding title}" />
                                            <TextBlock Grid.Column="1" Text="{Binding author}" />
                                        </Grid>
                                        <Grid Visibility="{Binding IsSelected, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource TemplatedParent}}">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition />
                                                <ColumnDefinition />
                                                <ColumnDefinition />
                                            </Grid.ColumnDefinitions>
                                            <Image Width="100"
                                                   HorizontalAlignment="Left"
                                                   Source="{Binding cover}" />
                                            <StackPanel Grid.Column="1">
                                                <TextBlock>
                                                    <Run Text="标题：" />
                                                    <Run Text="{Binding title}" />
                                                </TextBlock>
                                                <TextBlock Margin="0,12">
                                                    <Run Text="艺人：" />
                                                    <Run Text="{Binding author}" />
                                                </TextBlock>
                                                <StackPanel Orientation="Horizontal">
                                                    <Button MinWidth="60"
                                                            Command="{Binding Path=DataContext.PlayCommand,
                                                                              RelativeSource={RelativeSource AncestorType=Page}}"
                                                            CommandParameter="{Binding id}"
                                                            Content="播放" />

                                                    <Button MinWidth="60"
                                                            Margin="12,0"
                                                            Command="{Binding Path=DataContext.DownloadCommand,
                                                                              RelativeSource={RelativeSource AncestorType=Page}}"
                                                            CommandParameter="{Binding }"
                                                            Content="下载" />
                                                </StackPanel>
                                            </StackPanel>
                                        </Grid>
                                    </Grid>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </ListBox.ItemContainerStyle>
            </ListBox>

            <ListBox Grid.Column="2" ItemsSource="{Binding DownloadQueue}">
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="ListBoxItem">
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition />
                                            <ColumnDefinition Width="Auto" />
                                        </Grid.ColumnDefinitions>

                                        <ContentControl Content="{Binding Filename}" />
                                        <Path Grid.Column="1"
                                              Width="16"
                                              Height="16"
                                              Margin="0,0,0,0"
                                              Data="M8.2000655,15.977L12.388772,15.977 5.1336883,21.54196 12.696168,21.54196C12.912266,21.54196,13.110164,21.651355,13.206462,21.824446L14.950044,26.592542 27.716808,26.592542 29.458889,21.824446C29.557789,21.651355,29.753086,21.54196,29.970682,21.54196L37.531803,21.54196 30.277981,15.977 34.466736,15.977 41.258163,20.545904C42.268753,21.149977,42.872845,22.541917,42.60075,23.63817L41.404159,30.195185C41.133266,31.291538,39.931476,32.19,38.734993,32.19L3.9331414,32.19C2.7353441,32.19,1.533447,31.291538,1.2626997,30.195185L0.064715919,23.63817C-0.20609439,22.541917,0.39802514,21.149977,1.4097285,20.545904z M19.798,0L22.798,0 22.798,10.213962 22.836025,10.175905 27.698,5.316 27.698,9.5312901 23.413978,13.815516 23.378889,13.850619 23.395859,13.870221 21.288999,15.977001 19.18079,13.870221 14.897,9.5859852 14.897,5.3694649 19.757833,10.23191 19.798,10.272044z"
                                              Fill="OrangeRed"
                                              RenderTransformOrigin="0.5,0.5"
                                              Stretch="Uniform"
                                              Visibility="{Binding Completed,
                                                                   Converter={StaticResource BooleanToVisibilityInverseConverter}}">
                                            <Path.RenderTransform>
                                                <TransformGroup>
                                                    <TransformGroup.Children>
                                                        <RotateTransform Angle="0" />
                                                        <ScaleTransform ScaleX="1" ScaleY="1" />
                                                    </TransformGroup.Children>
                                                </TransformGroup>
                                            </Path.RenderTransform>
                                        </Path>

                                        <Path Grid.Column="1"
                                              Width="16"
                                              Height="16"
                                              Margin="0,0,0,0"
                                              Data="M-150.204,626.126C-152.317,626.126 -154.429,626.126 -156.541,626.126 -167.642,633.42 -180.629,646.047 -189.668,657.238 -190.916,658.782 -192.945,662.362 -193.701,662.422 -194.041,662.448 -198.024,659.719 -198.614,659.297 -202.818,656.279 -205.779,653.709 -209.257,650.899 -211.248,652.172 -212.879,653.805 -214.153,655.797 -206.627,665.074 -200.283,675.534 -193.124,685.18 -181.491,665.11 -168.473,644.683 -152.796,629.006 -151.735,627.946 -149.817,626.933 -150.204,626.126z"
                                              Fill="#FF007ACC"
                                              RenderTransformOrigin="0.5,0.5"
                                              Stretch="Uniform"
                                              Visibility="{Binding Completed,
                                                                   Converter={StaticResource BooleanToVisibilityConverter}}">
                                            <Path.RenderTransform>
                                                <TransformGroup>
                                                    <TransformGroup.Children>
                                                        <RotateTransform Angle="0" />
                                                        <ScaleTransform ScaleX="1" ScaleY="1" />
                                                    </TransformGroup.Children>
                                                </TransformGroup>
                                            </Path.RenderTransform>
                                        </Path>
                                    </Grid>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </ListBox.ItemContainerStyle>
            </ListBox>
        </Grid>



        <Grid Grid.Row="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <StackPanel Grid.Column="3" Orientation="Horizontal">

                <Button MinWidth="60"
                        Margin="12,0"
                        Command="{Binding PreviousCommand}"
                        Content="上一页" />

                <Button MinWidth="60"
                        Command="{Binding NextCommand}"
                        Content="下一页" />

            </StackPanel>
        </Grid>
    </Grid>
</Page>